package com.shop.cloud.util;

import java.io.StringWriter;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class TemplateUtils {

	
	public static String htmlTemplate(Map root) throws Exception{
		Configuration cfg = new Configuration();
        Template t = cfg.getTemplate("/src/main/resources/mail.tpl");  
          
        //最关键在这里，不使用与文件相关的Writer  
        StringWriter stringWriter=new StringWriter();  
          
        try  
        {  
            t.process(root, stringWriter);  
              
            //这里打印的就是通过模板处理后得到的字符串内容  
            System.out.println(stringWriter.toString());  
        } catch (TemplateException e)  
        {  
            e.printStackTrace();  
        } 
        return stringWriter.toString();
	}
}
